<?php
namespace app\modules\adminapi\controllers;

use fate\http\Request;
use app\models\Category;
use app\libs\Util;

class EditcategoryController extends \app\modules\adminapi\ForceLoginPure {

    public function run() {
        $req = Request::getInstance();

        $id = $req->getParameter('id');
        $pid = $req->getParameter('pid');
        $name = Util::plainText($req->getParameter('name'));

        if(!is_numeric($id) || !is_numeric($pid)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        if(!$name) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $data = [
            'pid' => $pid,
            'name' => $name
        ];
        // var_dump($data);exit;

        $model = new Category();
        $ret = $model->update($id, $data);

        $this->ajaxReturn(null);
    }

}
